home *** CD-ROM | disk | FTP | other *** search
/ PC Open 101 / PC Open 101 CD 1.bin / CD1 / INTERNET / EMAIL / pop file / setup.exe / pipe.pl < prev    next >
Encoding:
Perl Script  |  2004-09-03  |  2.8 KB  |  85 lines

  1. #!/usr/bin/perl
  2. # ---------------------------------------------------------------------------------------------
  3. #
  4. # pipe.pl --- Read a message in on STDIN and write out the modified version on STDOUT
  5. #
  6. # Copyright (c) 2001-2004 John Graham-Cumming
  7. #
  8. #   This file is part of POPFile
  9. #
  10. #   POPFile is free software; you can redistribute it and/or modify
  11. #   it under the terms of the GNU General Public License as published by
  12. #   the Free Software Foundation; either version 2 of the License, or
  13. #   (at your option) any later version.
  14. #
  15. #   POPFile is distributed in the hope that it will be useful,
  16. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. #   GNU General Public License for more details.
  19. #
  20. #   You should have received a copy of the GNU General Public License
  21. #   along with POPFile; if not, write to the Free Software
  22. #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. #
  24. # ---------------------------------------------------------------------------------------------
  25.  
  26. use strict;
  27. use lib defined($ENV{POPFILE_ROOT})?$ENV{POPFILE_ROOT}:'./';
  28. use POPFile::Loader;
  29.  
  30. # main
  31.  
  32. if ( $#ARGV == -1 ) {
  33.  
  34.     # POPFile is actually loaded by the POPFile::Loader object which does all
  35.     # the work
  36.  
  37.     my $POPFile = POPFile::Loader->new();
  38.  
  39.     # Indicate that we should create not output on STDOUT (the POPFile
  40.     # load sequence)
  41.  
  42.     $POPFile->debug(0);
  43.     $POPFile->CORE_loader_init();
  44.     $POPFile->CORE_signals();
  45.     $POPFile->CORE_load( 1 );
  46.     $POPFile->CORE_link_components();
  47.     $POPFile->CORE_initialize();
  48.  
  49.     # Ugly hack which is needed because Bayes::classify_and_modify looks up
  50.     # the UI port and whether we are allowing remote connections or not
  51.     # to set the XPL link in the header.  If we don't have these predefined
  52.     # then they'll be discarded when the configuration is loaded, and since
  53.     # we are not loading the UI, they are not defined at this point
  54.  
  55.     my $c = $POPFile->get_module('POPFile::Config');
  56.     $c->module_config_( 'html', 'local', 1 );
  57.     $c->module_config_( 'html', 'port',  8080 );
  58.  
  59.     if ( $POPFile->CORE_config() ) {
  60.  
  61.         # Prevent the tool from finding another copy of POPFile running
  62.  
  63.         $c->config_( 'piddir', $c->config_( 'piddir' ) . 'pipe.pl.' );
  64.  
  65.         # TODO: interface violation
  66.         $c->{save_needed__} = 0;
  67.  
  68.         $POPFile->CORE_start();
  69.  
  70.         my $b = $POPFile->get_module('Classifier::Bayes');
  71.         my $session = $b->get_session_key( 'admin', '' );
  72.  
  73.         $b->classify_and_modify( $session, \*STDIN, \*STDOUT, 1, '', 0, 1, "\n" );
  74.         $b->release_session_key( $session );
  75.         $POPFile->CORE_stop();
  76.     }
  77.  
  78.     exit 0;
  79. } else {
  80.     print "pipe.pl - reads a message on STDIN, classifies it, outputs the modified version on STDOUT\n\n";
  81.     print "Usage: pipe.pl\n";
  82.  
  83.     exit 1;
  84. }
  85.